<template>
  <div class="todo-input">
    <input
      v-model="taskText"
      @keyup.enter="submitTask"
      type="text"
      placeholder="添加新的待办事项"
    />
    <button @click="submitTask">添加</button>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const taskText = ref('')
const emit = defineEmits(['add-task'])

function submitTask() {
  const text = taskText.value.trim()
  if (text) {
    emit('add-task', text)
    taskText.value = ''
  }
}
</script>

<style scoped>
.todo-input {
  display: flex;
  margin-bottom: 20px;
}

.todo-input input {
  flex: 1;
  padding: 12px;
  font-size: 16px;
  border: 1px solid #ddd;
  border-radius: 4px 0 0 4px;
  outline: none;
  transition: border-color 0.3s;
}

.todo-input input:focus {
  border-color: #42b983;
}

.todo-input button {
  padding: 12px 20px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  font-weight: bold;
  transition: background-color 0.3s;
}

.todo-input button:hover {
  background-color: #3aa876;
}
</style> 